﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Action = MedicalAdviser.Portable.DataTypes.WsTypes.Action;
using Dts = MedicalAdviser.Portable.DataTypes;


namespace MedicalAdviser.Controllers
{
    public class ActionManager
    {

        public async static void MakeThisAysnc()
        {

            var firstTask = new Task(
               () =>        
                   GetNumber(23)
            ); 
             firstTask.Start();

        }

        public async  static void GetNumber(int a )
        {
              Thread.Sleep(1000 * 60);
              int val = a + 10;

        }


        public static int SaveAction(Dts.WsTypes.AppInteration action)
        {
            int ret = -1;
            if(action.Action == Action.ViewDrug )
            {
                /*Make this asnyc */
                new Task( () => MedicalAdviser.DAL.DbInserts.MarkViewDrug(action)).Start();
            }
            else
            {
                if (action.Action == Action.Keyword)
                {
                    ret = MedicalAdviser.DAL.DbInserts.SaveSearchKeyWord(action);
                }
                else
                {
                    if (action.Action ==  Action.RecommendDrug)
                    {
                        ret = MedicalAdviser.DAL.DbInserts.SaveSearchKeyWord(action);    
                    }
                }
            }

            return ret;
        }


    }
}
